package serverMgr

import (
	"fmt"
	"strings"

	"gitee.com/night-tc/gobige/common"
	"gitee.com/night-tc/gobige/global"
)

const (
	PATH_INFO   = "info"   //服务器信息
	PATH_LOAD   = "load"   //服务器负载
	PATH_STATUS = "status" //服务器状态
)

// 获取注册路径
func GetPath(groupid uint32, stype uint32, sid uint64) string {
	return fmt.Sprintf("server/%d/%d/%d/%s", stype, groupid, sid, PATH_INFO)
}

// 指定分组和类型的监听
func GetWatchPath(sGroup uint32, sType uint32) string {
	return fmt.Sprintf("server/%d/%d/", sType, sGroup)
}

// 获取写Load的路径
func GetPathLoad(groupid uint32, stype uint32, sid uint64) string {
	return fmt.Sprintf("server/%d/%d/%d/%s", stype, groupid, sid, PATH_LOAD)
}

// 获取写状态的路径
func GetPathStatus(groupid uint32, stype uint32, sid uint64) string {
	return fmt.Sprintf("server/%d/%d/%d/%s", stype, groupid, sid, PATH_STATUS)
}

// 折路径
func GetPathServerInfo(pathname string) (groupid uint32, stype uint32, sid uint64) {
	sli := strings.Split(pathname, "/")
	if len(sli) >= 4 {
		return uint32(common.NewString(sli[2]).ToIntV()), uint32(common.NewString(sli[1]).ToIntV()), uint64(common.NewString(sli[3]).ToIntV())
	}
	return 0, 0, 0
}

// 根据类型监听服务器
func GetWatchByType(sType global.ServerTypeEnum) string {
	return fmt.Sprintf("server/%d/", sType)
}
